/**
 * Created by fupeng on 17/2/16.
 */
/**
 * Created by Administrator on 2017/2/13.
 */
var cinemaDetailDao = require('../dao/CinemaDetailDao');
var cinemaCollectionDao = require('../dao/CinemaCollectionDao');
var memberDao = require('../dao/MemberDao');
var async = require('async');

module.exports = {

    /**
     * @param req
     * @param callback
     * http -- post -- ajax
     * rout:cinemaDetail
     */
    getCinemaDetailInfoModel: function (req,callback) {
    var cinema_code = 0; //影吧id
    var open_id ='0';
    if(req.signedCookies.openid||req.signedCookies.open_id){
        open_id = req.signedCookies.openid||req.signedCookies.open_id;
    }
    if(req.query.cinema_code){
        cinema_code = req.query.cinema_code;
    };
        var resultData = {};//结果集
        async.parallel({
            cinemaDetail: function (callBack) {
                cinemaDetailDao.getCinemaDetail(cinema_code, function (data) {
                    if (data.isSuccess) {
                        callBack(null, data.rows[0])
                    } else {

                    }
                });
            },
            isCollection: function (callBack) {
                memberDao.selectByopenid(open_id, function (data) {
                    if (data.rows[0]) {
                        var member_id = data.rows[0].member_id;
                        cinemaCollectionDao.selectCinemaCollectionByMemberidAndCinemaCode([member_id, cinema_code], function (data) {
                            if (data.isSuccess) {
                                if (data.rows[0]) {
                                    callBack(null, true);
                                } else {
                                    callBack(null, false);
                                }
                            } else {
                                callBack(null, false);
                            }
                        })
                    } else {
                        callBack(null, false);
                    }

                })
            }
        }, function (err, result) {
            if (err) {
                resultData = {
                    layout: false,
                    message: 'error',
                    status: 'error'
                };
            } else {
                resultData = {
                    title: '影吧详情',
                    layout: false,
                    message: 'success',
                    status: 'success',
                    cinemaDetail: result.cinemaDetail,
                    isCollection: result.isCollection
                };
            };
            callback(resultData);
        });
    }
};

